//
//  XYPerson.m
//  XYTest
//
//  Created by YaoZhaofeng on 16/6/8.
//  Copyright © 2016年 YaoZhaofeng. All rights reserved.
//

#import "XYPerson.h"
#import <objc/runtime.h>
@implementation XYPerson
- (NSDictionary *)allProperties {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    
    unsigned int count = 0;
    objc_property_t *properties = class_copyPropertyList([self class], &count);
    for (NSUInteger  i = 0; i < count; i++) {
        const char *name = property_getName(properties[i]);
        const char *attribute = property_getAttributes(properties[i]);
        NSString *nameString = [NSString stringWithUTF8String:name];
        NSString *attributeString = [NSString stringWithUTF8String:attribute];
        dict[nameString] = attributeString;
    }
    
    return [dict copy];
}

- (void)action:(id)sender{
    
}

+ (void)initialize {
    NSLog(@"initialize::className = %@", NSStringFromClass([self class]));
}

//- (NSString *)description {
//    
//    NSMutableString* text = [NSMutableString stringWithFormat:@"<%@> \n", NSStringFromClass([self class])];
//    unsigned int count = 0;
//    objc_property_t *properties = class_copyPropertyList([self class], &count);
//    for (NSUInteger  i = 0; i < count; i++) {
//        const char *name = property_getName(properties[i]);
//        NSString *nameString = [NSString stringWithUTF8String:name];
//        NSLog(@"nameString::%@",nameString);
//        if ([nameString isEqualToString:@"hash"] || [nameString isEqualToString:@"superclass"] || [nameString isEqualToString:@"description"]|| [nameString isEqualToString:@"debugDescription"]) {
//            continue;
//        }
//        id value = [self valueForKey:nameString];
//        NSString* valueDescription = value ?[value description]:@"<nil>";
//        [text appendFormat:@"   [%@]: %@\n", nameString, valueDescription];
//    }
//    [text appendFormat:@"</%@>", NSStringFromClass([self class])];
//    return text;
//}

@end
